#! /bin/bash
# 消耗CPU的测试脚本

endless_loop()
{
  /bin/bash -c "while true; do i=1/1; done" &
}

echo "USAGE: $0 [CPUs]"

cpus=$1
# keep 1 core left by default
[ -n "$cpus" ] || cpus=`grep processor /proc/cpuinfo|tail -n 1|awk '{print $3}'`

pids=""
for i in `seq $cpus`
do
  endless_loop
  pids=`echo $pids $!`
done

echo "kill $pids"

echo "Press any key to stop ..."
read input

#exec 2 > /dev/null

kill $pids

